﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LPLS.Common.DBModule
{


    /// <summary>
    /// 枚举类型，表示不同的数据库键值
    /// </summary>
    public enum DatabaseEnum
{
    [Description("SqlServer1")]
    SqlServer1,
    [Description("SqlServer2")]
    SqlServer2,
    [Description("MySql1")]
    MySql1,
    [Description("MySql2")]
    MySql2,
    [Description("Sqlite1")]
    Sqlite1,
    [Description("Sqlite2")]
    Sqlite2
}

    /// <summary>
    /// 特性用于获取枚举的描述字符串
    /// </summary>
    public class DescriptionAttribute : Attribute
{
    public string Description { get; }

    public DescriptionAttribute(string description)
    {
        Description = description;
    }
}

    /// <summary>
    /// 扩展方法用于获取枚举的描述字符串
    /// </summary>
    public static class EnumExtensions
{
    public static string GetDescription(this Enum value)
    {
        var fieldInfo = value.GetType().GetField(value.ToString());
        var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
        return attributes.Length > 0 ? attributes[0].Description : value.ToString();
    }
}

}
